home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / filed39a.zip / file.man < prev    next >
Text File  |  1993-08-07  |  15KB  |  397 lines

  1.  
  2.  
  3.  
  4. FILE(1)                                                   FILE(1)
  5.  
  6.  
  7. NNAAMMEE
  8.        _f_i_l_e - determine file type
  9.  
  10. SSYYNNOOPPSSIISS
  11.        ffiillee [ --cc ] [ --zz ] [ --LL ] [ --ff namefile ] [ --mm magicfile ]
  12.        file ...
  13.  
  14. DDEESSCCRRIIPPTTIIOONN
  15.        _F_i_l_e tests each argument in an  attempt  to  classify  it.
  16.        There  are  three  sets of tests, performed in this order:
  17.        filesystem tests, magic number tests, and language  tests.
  18.        The  _f_i_r_s_t  test  that succeeds causes the file type to be
  19.        printed.
  20.  
  21.        The type printed will usually contain  one  of  the  words
  22.        tteexxtt (the file contains only ASCII characters and is prob-
  23.        ably safe to read on an ASCII terminal),  eexxeeccuuttaabbllee  (the
  24.        file  contains the result of compiling a program in a form
  25.        understandable to some UNIX kernel or  another),  or  ddaattaa
  26.        meaning  anything  else  (data is usually `binary' or non-
  27.        printable).  Exceptions are well-known file formats  (core
  28.        files,  tar  archives)  that  are  known to contain binary
  29.        data.  When modifying the file _/_e_t_c_/_m_a_g_i_c or  the  program
  30.        itself,  pprreesseerrvvee tthheessee kkeeyywwoorrddss ..  People depend on know-
  31.        ing that all the readable files in a  directory  have  the
  32.        word  ``text'' printed.  Don't do as Berkeley did - change
  33.        ``shell commands text'' to ``shell script''.
  34.  
  35.        The filesystem tests are based  on  examining  the  return
  36.        from  a _s_t_a_t(2) system call.  The program checks to see if
  37.        the file is empty, or if it's some sort of  special  file.
  38.        Any  known  file  types  appropriate to the system you are
  39.        running  on  (sockets,  symbolic  links,  or  named  pipes
  40.        (FIFOs) on those systems that implement them) are intuited
  41.        if they are defined in the system header file  ssyyss//ssttaatt..hh.
  42.  
  43.        The  magic  number  tests are used to check for files with
  44.        data in particular fixed formats.  The  canonical  example
  45.        of  this  is  a binary executable (compiled program) aa..oouutt
  46.        file, whose format is  defined  in  aa..oouutt..hh  and  possibly
  47.        eexxeecc..hh  in  the  standard  include directory.  These files
  48.        have a `magic number' stored in a  particular  place  near
  49.        the  beginning  of  the file that tells the UNIX operating
  50.        system that the file is a binary executable, and which  of
  51.        several  types thereof.  The concept of `magic number' has
  52.        been applied by extension to data files.   Any  file  with
  53.        some invariant identifier at a small fixed offset into the
  54.        file can usually be described in this way.   The  informa-
  55.        tion   in   these  files  is  read  from  the  magic  file
  56.        _/_e_t_c_/_m_a_g_i_c_.
  57.  
  58.        If an argument appears to be an ASCII file, _f_i_l_e  attempts
  59.        to  guess  its language.  The language tests look for par-
  60.        ticular strings (cf _n_a_m_e_s_._h) that can appear  anywhere  in
  61.  
  62.  
  63.  
  64.                    Copyright but distributable                  1
  65.  
  66.  
  67.  
  68.  
  69.  
  70. FILE(1)                                                   FILE(1)
  71.  
  72.  
  73.        the  first few blocks of a file.  For example, the keyword
  74.        ..bbrr indicates that the file is most likely a  troff  input
  75.        file,  just  as  the keyword ssttrruucctt indicates a C program.
  76.        These tests  are  less  reliable  than  the  previous  two
  77.        groups,  so  they  are  performed last.  The language test
  78.        routines also  test  for  some  miscellany  (such  as  _t_a_r
  79.        archives)  and determine whether an unknown file should be
  80.        labelled as `ascii text' or `data'.
  81.  
  82.        Use --mm _f_i_l_e to specify an alternate file of magic numbers.
  83.  
  84.        The --zz tries to look inside compressed files.
  85.  
  86.        The  --cc  option  causes  a checking printout of the parsed
  87.        form of the magic file.  This is usually used in  conjunc-
  88.        tion  with  --mm to debug a new magic file before installing
  89.        it.
  90.  
  91.        The --ff _n_a_m_e_f_i_l_e option specifies that  the  names  of  the
  92.        files  to  be  examined are to be read (one per line) from
  93.        _n_a_m_e_f_i_l_e before the argument list.  Either _n_a_m_e_f_i_l_e or  at
  94.        least  one  filename argument must be present; to test the
  95.        standard input, use ``-'' as a filename argument.
  96.  
  97.        The --LL option causes symlinks to be followed, as the like-
  98.        named option in _l_s(1).
  99.  
  100. FFIILLEESS
  101.        _/_e_t_c_/_m_a_g_i_c - default list of magic numbers
  102.  
  103. SSEEEE AALLSSOO
  104.        _m_a_g_i_c(4) - description of magic file format.
  105.        _S_t_r_i_n_g_s(1), _o_d(1) - tools for examining non-textfiles.
  106.  
  107. SSTTAANNDDAARRDDSS CCOONNFFOORRMMAANNCCEE
  108.        This  program is believed to exceed the System V Interface
  109.        Definition of FILE(CMD), as near as one can determine from
  110.        the  vague  language  contained therein.  Its behaviour is
  111.        mostly compatible with the System V program  of  the  same
  112.        name.   This version knows more magic, however, so it will
  113.        produce different (albeit more accurate)  output  in  many
  114.        cases.
  115.  
  116.        The  one  significant  difference between this version and
  117.        System V is that this version treats any white space as  a
  118.        delimiter,  so  that  spaces  in  pattern  strings must be
  119.        escaped.  For example,
  120.        >10  string    language impress    (imPRESS data)
  121.        in an existing magic file would have to be changed to
  122.        >10  string    language\ impress   (imPRESS data)
  123.        In addition, in this version, if a pattern string contains
  124.        a backslash, it must be escaped.  For example
  125.        0    string         \begindata     Andrew Toolkit document
  126.        in an existing magic file would have to be changed to
  127.  
  128.  
  129.  
  130.                    Copyright but distributable                  2
  131.  
  132.  
  133.  
  134.  
  135.  
  136. FILE(1)                                                   FILE(1)
  137.  
  138.  
  139.        0    string         \\begindata    Andrew Toolkit document
  140.  
  141.        SunOS releases 3.2 and later from Sun Microsystems include
  142.        a _f_i_l_e(1) command derived from the System V one, but  with
  143.        some  extensions.   My  version differs from Sun's only in
  144.        minor ways.  It includes the extension of the  `&'  opera-
  145.        tor, used as, for example,
  146.        >16  long&0x7fffffff     >0        not stripped
  147.  
  148. MMAAGGIICC DDIIRREECCTTOORRYY
  149.        The  magic  file  entries have been collected from various
  150.        sources,  mainly  USENET,  and  contributed   by   various
  151.        authors.   Ian  Darwin  (address below) will collect addi-
  152.        tional or corrected magic file entries.   A  consolidation
  153.        of magic file entries will be distributed periodically.
  154.  
  155.        The  order  of  entries  in the magic file is significant.
  156.        Depending on what system you are  using,  the  order  that
  157.        they  are put together may be incorrect.  If your old _f_i_l_e
  158.        command uses a magic file, keep the old magic file  around
  159.        for comparison purposes (rename it to _/_e_t_c_/_m_a_g_i_c_._o_r_i_g).
  160.  
  161. HHIISSTTOORRYY
  162.        There has been a _f_i_l_e command in every UNIX since at least
  163.        Research Version 6 (man page dated  January,  1975).   The
  164.        System  V version introduced one significant major change:
  165.        the external list of magic number types.  This slowed  the
  166.        program down slightly but made it a lot more flexible.
  167.  
  168.        This  program,  based on the System V version, was written
  169.        by Ian Darwin without looking  at  anybody  else's  source
  170.        code.
  171.  
  172.        John  Gilmore revised the code extensively, making it bet-
  173.        ter than the first version.  Geoff Collyer  found  several
  174.